﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Sicurezza.CA.Manager;

namespace Sicurezza.CA.Server.Controlli
{
    public partial class RequestControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            // Visualizza Request
            e.Cancel = true;
            string ReqId = GridView1.Rows[e.NewEditIndex].Cells[0].Text;
            TextBox1.Text = RequestManager.Get(ReqId);
            MultiView1.ActiveViewIndex = 3;

        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            // Accetta Request
            e.Cancel = true;
            daystxt.Text = "";
            string ReqId = GridView1.Rows[e.RowIndex].Cells[0].Text;
            ViewState["ReqId"] = ReqId;
            MultiView1.ActiveViewIndex = 2;
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 0;
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // Rifiuta Request
            e.Cancel = true;
            Reasontxt.Text = "";
            string ReqId = GridView1.Rows[e.RowIndex].Cells[0].Text;
            ViewState["ReqId"] = ReqId;
            MultiView1.ActiveViewIndex = 1;
        }

        protected void Button4_Click(object sender, EventArgs e)
        {

            MultiView1.ActiveViewIndex = 0;
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            string ReqId = ViewState["ReqId"].ToString();
            string reason = Reasontxt.Text;
            RequestManager.Reject(ReqId, reason);
            MultiView1.ActiveViewIndex = 0;
            GridView1.DataBind();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

            MultiView1.ActiveViewIndex = 0;
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            string ReqId = ViewState["ReqId"].ToString();
            int days = Convert.ToInt32(daystxt.Text);
            RequestManager.Accept(ReqId,days);
            MultiView1.ActiveViewIndex = 0;
            GridView1.DataBind();
        }


    }
}